from pydantic_settings import BaseSettings
from typing import Optional
import os

class Settings(BaseSettings):
    """
    应用配置类
    使用pydantic-settings管理配置项
    """
    # 数据库配置
    database_url: str = "postgresql://postgres:password@localhost:5432/aihub_db"
    
    # JWT配置
    secret_key: str = "your-secret-key-here-change-in-production"
    algorithm: str = "HS256"
    access_token_expire_minutes: int = 30
    
    # Redis配置
    redis_url: str = "redis://localhost:6379/0"
    
    # 文件上传配置
    upload_dir: str = "./uploads"
    max_file_size: int = 10485760  # 10MB
    allowed_image_types: str = "image/jpeg,image/png,image/gif"
    allowed_video_types: str = "video/mp4,video/avi,video/mov"
    allowed_audio_types: str = "audio/mp3,audio/wav,audio/aac"
    
    # 微信配置
    wechat_app_id: Optional[str] = None
    wechat_app_secret: Optional[str] = None
    
    # 开发环境配置
    debug: bool = True
    environment: str = "development"
    host: str = "0.0.0.0"
    port: int = 8000
    
    # CORS配置
    cors_origins: list = ["http://localhost:5173", "http://127.0.0.1:3000"]
    
    class Config:
        env_file = ".env"
        case_sensitive = False

# 创建全局配置实例
settings = Settings()

# 确保上传目录存在
os.makedirs(settings.upload_dir, exist_ok=True)
os.makedirs(os.path.join(settings.upload_dir, "avatars"), exist_ok=True)
os.makedirs(os.path.join(settings.upload_dir, "works"), exist_ok=True)
os.makedirs(os.path.join(settings.upload_dir, "thumbnails"), exist_ok=True)